<template>
  <div class="operation-log-list">
    <a-form layout="inline">
      <a-form-item label="">
        <a-input
          v-model="queryParam.modelUuid"
          placeholder="输入模型编号"
          :style="{
            width: '200px',
          }"
        />
      </a-form-item>
      <a-form-item label="">
        <a-input
          v-model="queryParam.name"
          placeholder="输入模型名称"
          :style="{
            width: '200px',
          }"
        />
      </a-form-item>
      <a-form-item label="">
        <a-input
          v-model="queryParam.version"
          placeholder="输入模型版本"
          :style="{
            width: '200px',
          }"
        />
      </a-form-item>
      <a-form-item label="">
        <a-button type="primary" @click="searchHandle">搜索</a-button>
      </a-form-item>
    </a-form>
    <s-table
      ref="table"
      size="default"
      rowKey="id"
      :columns="columns"
      :data="loadData"
      :alert="false"
      showPagination="auto"
      class="python-batch-testing-table"
    >
      <template slot="name" slot-scope="text, record">
        <a-tooltip>
          <template slot="title">{{ record.name }}</template>
          {{ record.name }}
        </a-tooltip>
      </template>
      <span slot="testData" slot-scope="text, record">
        <a-button type="link" @click="handleDetail(record.testData)">详情</a-button>
      </span>
      <span slot="runResult" slot-scope="text, record">
        <a-button type="link" @click="handleDetail(record.runResult)">详情</a-button>
      </span>
    </s-table>
    <a-modal title="操作内容" :visible="visible" @ok="visible = false" @cancel="visible = false" width="800px">
      <VueJsonPretty :data="operContent" />
    </a-modal>
  </div>
</template>

<script>
import Vue, { defineComponent } from 'vue'
import { STable } from '@/components'
import VueJsonPretty from 'vue-json-pretty'
import 'vue-json-pretty/lib/styles.css'
import VCA from '@vue/composition-api'
import JsonEditorVue from 'json-editor-vue'
import { getPythonBatchTesting } from '@/api/modelLog'
import moment from 'moment'

Vue.use(VCA)
const columns = [
  {
    title: '模型编号',
    dataIndex: 'uuid',
    width: 120,
  },
  {
    title: '模型名称',
    dataIndex: 'name',
    width: 120,
    scopedSlots: { customRender: 'name' },
  },
  {
    title: '模型版本',
    dataIndex: 'version',
    width: 80,
  },
  {
    title: '测试人员',
    dataIndex: 'testMan',
    width: 80,
  },
  {
    title: '执行消耗时间',
    dataIndex: 'runTime',
    width: 120,
  },
  {
    title: '执行时间',
    dataIndex: 'gmtCreate',
    width: 180,
    customRender: (text, record) => {
      return moment(text).format('YYYY-MM-DD HH:mm:ss')
    },
  },
  {
    title: '测试数据',
    scopedSlots: { customRender: 'testData' },
    width: 100,
    dataIndex: 'testData',
    fixed: 'right',
  },
  {
    title: '执行结果',
    scopedSlots: { customRender: 'runResult' },
    width: 100,
    dataIndex: 'runResult',
    fixed: 'right',
  },
]
export default defineComponent({
  name: 'PythonBatchTesting',
  components: {
    STable,
    VueJsonPretty,
    JsonEditorVue,
  },
  props: {},
  data() {
    return {
      columns,
      visible: false,
      queryParam: {},
      operContent: '',
    }
  },
  mounted() {},
  methods: {
    searchHandle() {
      this.$refs.table.refresh(true)
    },
    loadData(parameter) {
      const requestParameters = Object.assign(
        {},
        {
          curPage: parameter.pageNo,
          pageSize: parameter.pageSize,
        },
        this.queryParam
      )

      console.log('loadData request parameters:', requestParameters)
      return getPythonBatchTesting(requestParameters).then((res) => {
        return res.data
      })
    },
    handleDetail(data) {
      this.visible = true
      this.operContent = JSON.parse(data)
    },
  },
})
</script>

<style lang="less" scoped>
.operation-log-list {
  .python-batch-testing-table {
    margin-top: 16px;
  }
}
</style>
